/*
package com.atguigu.tingshu.common.Thread;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

*/
/**
 * projectName: tingshu-parent
 *
 * @author: 王宝贵
 * time: 2024/10/28 19:33 周一
 * description:
 *//*

//@Configuration
public class ThreadPoolConfig {

    //1.动态得到线程数 IO密集型：CPU逻辑处理器个数*2
    int processorsCount = Runtime.getRuntime().availableProcessors();
    int coreCount = processorsCount * 2;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                coreCount,
                coreCount,
                0,
                TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new RejectedExecutionHandler() {
                    @Override
                    public void rejectedExecution(Runnable r, java.util.concurrent.ThreadPoolExecutor executor) {
                        //r:被拒绝任务  executor :线程池对象
                        //自定义拒绝策略：重试-将任务再次提交给线程执行
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        executor.submit(r);
                    }
                });

        //先运行1个核心线程
        threadPoolExecutor.prestartCoreThread();
        //两个就是启动两次

        return threadPoolExecutor;
    }


}*/
